package com.itheima.controller;


import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping(value = {"/annotation"})
public class AnnotationLearn {

    @RequestMapping(value = "/requestParam", method = RequestMethod.GET)
    public String testRequestParam(
            @RequestParam(value = "name")
                    String username) {
        System.out.println(username);
        return "success";
    }


    @RequestMapping(value = "/requestBody", method = RequestMethod.POST)
    public String testRequestBody(@RequestBody String body)
    {
        System.out.println(body);
        return "success";
    }


    @RequestMapping(value = "/pathVariable/{hello}")
    public String testPathVariable(@PathVariable(value = "hello") Integer id)
    {
        System.out.println(id);
        return "success";
    }


    @RequestMapping(value = "/hiddenHttpMethodFilter/{hello}", method = RequestMethod.DELETE)
    public String testHiddenHttpMethodFilter(@PathVariable(value = "hello") Integer id)
    {
        System.out.println(id);
        return "success";
    }


    @RequestMapping(value = "/requestHeader")
    public String testRequestHeader(@RequestHeader(value = "Accept-Language") String headers)
    {
        System.out.println(headers);



//        Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
//Accept-Encoding: gzip, deflate, br
//Accept-Language: zh-CN,zh;q=0.9,en;q=0.8
//Cache-Control: max-age=0
//Connection: keep-alive
//Content-Length: 55
//Content-Type: application/x-www-form-urlencoded
//Cookie: JSESSIONID=B62F1D623422D0E49C5F55D09A8764CA; Phpstorm-f942f238=dc94a5e6-5bd8-411f-8721-9160206c5a1d
//Host: localhost:8080
//Origin: http://localhost:8080
//Referer: http://localhost:8080/spring_mvc_war/
//Sec-Fetch-Dest: document
//Sec-Fetch-Mode: navigate
//Sec-Fetch-Site: same-origin
//Sec-Fetch-User: ?1
//Upgrade-Insecure-Requests: 1
//User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36
        return "success";
    }



    @RequestMapping(value = "/cookieValue")
    public String testCookieValue(@CookieValue(value = "JSESSIONID", required = false) String cookieValue) {

        System.out.println(cookieValue);
        return "success";
    }

    @ModelAttribute
    public void modelAttr()
    {
        System.out.println("执行了...ModelAttribute");
    }


    @RequestMapping(value = "/modelAttribute")
    public String testModelAttribute()
    {
        return "success";
    }

}
